package com.test.config.granteConfig;

import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;

import static java.lang.System.out;

/**
 * @ClassName MyDeniedHandler
 * @Discription TODO
 * @Author DaiFuqiang
 * @Date 2022/11/20 20:52
 */
public class MyDeniedHandler implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {
        response.setContentType("application/json;charset=utf-8");
        PrintWriter out = null;
        try {
            out = response.getWriter();
        } catch (IOException ioException) {
            ioException.printStackTrace();
        }
        out.write("没有相关权限");
        out.flush();
        out.close();
    }
}

